package com.bubblegumproject.ogo.swing;

import com.bubblegumproject.ogo.action.TypeParameterizedAction;
import com.bubblegumproject.ogo.component.ComponentInstance;

/**
 * Action generated when an UIActivity has stopped and the user will no longer interact with it.
 *
 * @author Azubuko Obele (buko.obele@gmail.com)
 */
public class UIActivityStoppedAction<T extends UIActivity> extends UIActivityAction
        implements TypeParameterizedAction {

    private T uiActivity;

    public UIActivityStoppedAction(T uiActivity) {
        assert(uiActivity != null);
        this.uiActivity = uiActivity;
    }

    public T getUIActivity() {
        return uiActivity;
    }

    public Class getTypeParameter() {
        // SMELL: If the activity is a component then return its real component class, not the cglib generated class
        // this is a little bit of a smell...
        if (uiActivity instanceof ComponentInstance) {
            return uiActivity.getClass().getSuperclass();
        } else {
            return uiActivity.getClass();
        }
    }

    public String toString() {
        return getClass().getSimpleName() + "[" + uiActivity + "]";
    }
}
